<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRechargeTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //充值记录表
        Schema::create('recharge_records', function (Blueprint $table) {
            $table->increments('id');
            $table->string('sn')->nullable()->comment('充值流水号');
            $table->integer('user_id')->comment('用户id');
            $table->integer('templet_id')->comment('充值模板id');
            $table->enum('status', ['wait', 'success', 'fail', 'close'])->default('wait')->comment('充值状态');
            $table->enum('type', ['user', 'system'])->comment('充值方式， 用户充值、系统赠送');
            $table->string('pay_way')->nullabel()->comment('支付方式');
            $table->integer('pay_amount')->nullabel()->comment('支付金额');
            $table->string('pay_sn')->nullabel()->comment('支付流水号');
            $table->integer('amount')->comment('用户到账金额');
            $table->timestamps();
        });

        //充值模板表
        Schema::create('recharge_templets', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->comment('模板名字');
            $table->integer('amount')->comment('金额');
            $table->enum('status', ['enabled', 'disabled'])->default('enabled')->comment('是否启用');
            $table->timestamps();
        });

        //充值设置表
        Schema::create('recharge_limits', function (Blueprint $table) {
            $table->increments('id');
            $table->enum('ailpay', ['enabled', 'disabled'])->default('enabled')->comment('是否允许支付宝充值');
            $table->enum('wechat', ['enabled', 'disabled'])->default('enabled')->comment('是否允许微信充值');
            $table->integer('day_frequency')->default(1024)->comment('日充值次数限制');
            $table->integer('day_amount')->default(10000)->comment('日充值金额限制');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('recharge_records');
        Schema::dropIfExists('recharge_templets');
        Schema::dropIfExists('recharge_limits');
    }
}
